import React, { useEffect, useState } from 'react'
import './editDialog.scss'
import { Space, Button, Modal, Input } from 'antd'
import axios from 'axios';
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
import ModifyForm from '@/components/Form/modifyForm';
import { formList } from "./option"

export default function EditDialog(props: any) {
    const { dialogVisible, onSubmit, title, initialValues } = props
    const [open, setOpen] = useState(false)

    useEffect(() => {
        setOpen(props.dialogVisible)
    }, [props])

    const cancel = () => {
        setOpen(false)
    }
    // 提交编辑信息
    const submit = (value: any) => {
        if (title === '新增') {
            //发送请求
            axios.post('/api/plan/addType', value).then((res) => {
                setOpen(false)
                onSubmit()
            })
        } else {
            let params = {
                id: initialValues.id,
                ...value
            }
            axios.post('/api/plan/editType', params).then((res) => {
                setOpen(false)
                onSubmit()
            })
        }

    }
    return (
        <>
            {/* 新增页面 */}
            < Modal
                title={title}
                destroyOnClose={true}
                centered
                footer={null}
                open={open}
                width={1000}
                onCancel={cancel}
            >
                <ModifyForm formList={formList} onSubmit={submit} initialValues={initialValues} onCancel={cancel}>
                </ModifyForm>
            </Modal >
        </>
    )
}
